﻿#ifndef _PLANEMGR_H
#define _PLANEMGR_H
#include "base/core/singleton.h"
#include "base/core/object_pool.h"
#include "Common/CharacterDefine.h"
#include "Common/MessageDispatch/IMessageDispatch.h"
#include "Common/Event/Event.h"
#include "Common/TableData/PlanePlaneCfg.h"
#include <map>
class CPlane;
class Creature;
enum enPlaneType
{
	enPlaneType_Task =1,		//任务 
};
//位面管理�?
class CPlaneMgr : public ManualSingleton<CPlaneMgr>, public IClientMessageHandler
{
	friend class ManualSingleton<CPlaneMgr>;
public:
	virtual void		onClientMessage(uint32_t actionId, RECV_PACKAGE &package, uint64_t Id = 0);
	virtual const char* getClientHandlerDebugInfo(void){ return "CPlaneMgr::onClientMessage"; };

	void OnHandleOpenPlane(RECV_PACKAGE &package);
	void OnHandleClosePlane(RECV_PACKAGE &package);
public:
	CPlaneMgr();
	~CPlaneMgr();
	bool Init();
	bool UnInit();
	bool IsCanCreatePlane(const PlanePlaneCfgInfo& cfgInfo, Creature * pCreature);
	//创建位面
	//CharIDType cid 创建位面的玩家ID
	//std::vector<uint32_t> & vNpcConfigID  需要在位面中可见的NPC
	//isTeamFlag 为true表示是组队位面，否则为非组队位面
	//返回位面ID
	uint64_t CreatePlane(CharIDType cid, std::vector<uint32_t> & vNpcConfigID, std::vector<uint32_t> * pEffectID = NULL, uint32_t planeConfigID = 0, bool isTeamFlag = false);
	uint64_t CreatePlane(CharIDType cid,int32_t planeConfigID,bool isTeamFlag=false);
	void DestroyPlane(CharIDType cid,int32_t planID,bool bNoticeFlag=true);
	void DestroyPlaneByPlaneID(uint64_t planeID);
	std::vector<uint64_t>  GetPlaneNoPlayerList(uint64_t planeID);
	std::vector<uint64_t>  GetPlanePlayerList(uint64_t planeID);
	bool LeavePlane(uint64_t cid);
	//向指定位面添加怪物
	void AddCreature(uint64_t planeID, std::vector<uint64_t> & vCid);
	void AddCreature(uint64_t planeID, CharIDType cid);
	void AddCreature(uint64_t planeID, std::vector<uint32_t> & vNpcConfigid);
	bool IsInPlane(uint64_t planeID,CharIDType cid);
	CPlane * GetPlane(uint64_t planeID);
	//移除
	void RemoveCreature(uint64_t planeID, std::vector<uint64_t> & vCid);
	void RemoveCreature(uint64_t planeID, CharIDType cid);
	void RemoveCreature(uint64_t planeID, std::vector<uint32_t> & vNpcConfigid);

	//获取当前位面的配置ID
	uint32_t GetPlaneConfigId(uint64_t planeID);
private:
	std::map<uint64_t, CPlane*> m_mapMgr;
	ObjectPool<CPlane>*	m_planePool;
	uint64_t  m_i64PlaneNum;
};


#define g_MakePlaneMgr() (CPlaneMgr::Instance())
#define g_GetPlaneMgr()  (CPlaneMgr::GetInstance())
#define g_DelPlaneMgr()  (CPlaneMgr::Destroy())

#endif